home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 315.adf / Surf / gadgetuse.c < prev    next >
C/C++ Source or Header  |  1990-02-14  |  6KB  |  247 lines

  1. /* this file contains definition for the screen */
  2.  
  3. #include "scrnio.ih"
  4. #include <exec/memory.h>
  5. #ifdef MANX
  6. #include <functions.h>
  7. #endif
  8.  
  9. #include "scrndef.h"
  10. #include "gadgetdef.h"
  11. #include "mytypes.h"
  12. #include "poly.h"
  13. #include "readilbm.h"
  14.  
  15. #define GetExtens(gei) ((struct GadExtens *)gei->UserData)
  16.  
  17.  
  18. void GadgetSetVal(gad)
  19.     struct Gadget *gad;
  20. {
  21.     struct GadExtens *vp;
  22.     struct PropInfo *prop;
  23.     long gadval;
  24.  
  25.     if( !(gad->GadgetType & PROPGADGET) ) {
  26.         return;
  27.     }
  28.  
  29.     if( !gad->GadgetRender ) {
  30.         gad->GadgetRender = (APTR) malloc(sizeof(struct Image));
  31.         if( !gad->GadgetRender ) {
  32.             OutErr("Not enough memory for gadgets");
  33.             CloseDisplay();
  34.             exit( 0 );
  35.         }
  36.     }
  37.     if( !gad->SpecialInfo ) {
  38.         static struct PropInfo dummyprop = {
  39.             FREEHORIZ|AUTOKNOB,
  40.             0x8000, 1, /* HorizPot = initial value */
  41.             0xff, 0, /* not really of interest */
  42.             0,0,0,0,0,0
  43.         };
  44.  
  45.         gad->SpecialInfo = (APTR) malloc(sizeof(struct PropInfo));
  46.         if( !gad->SpecialInfo ) {
  47.             OutErr("Not enough memory for gadgets");
  48.             CloseDisplay();
  49.             exit( 0 );
  50.         }
  51.         *(struct PropInfo *)gad->SpecialInfo = dummyprop;
  52.     }
  53.  
  54.     vp = GetExtens( gad );
  55.     if(!vp)  {
  56.         return;
  57.     }
  58.     prop = (struct PropInfo *) gad->SpecialInfo;
  59.  
  60.     if( vp->isfloat ) {
  61.         gadval = (long)( (long)MAXPOT *
  62.             ( vp->curfval - vp->minfval )/(vp->maxfval - vp->minfval));
  63.         prop->HorizBody = MAXPOT /( 15 * 8 );
  64.     }
  65.     else {
  66.         gadval = ( (long)MAXPOT *
  67.             ( (long) vp->curival - vp->minival))/(vp->maxival - vp->minival);
  68.         prop->HorizBody = MAXPOT /( vp->maxival - vp->minival );
  69.     }
  70.  
  71.     prop->HorizPot = gadval;
  72. }
  73.  
  74.  
  75.  
  76. void GadgetUpdate(gad, exists)
  77.     struct Gadget *gad;
  78.     bool exists; /* has the gadget already been displayed? */
  79. {
  80.     struct GadExtens *vp;
  81.     long potvalue;
  82.     char dbuff[25];
  83.     char *tx, *dx;
  84.     struct IntuiText *it;
  85.  
  86.     if(!( gad->GadgetType & PROPGADGET) ) {
  87.         return;
  88.     }
  89.  
  90.     vp = GetExtens( gad );
  91.     if(!vp) return;
  92.  
  93.     potvalue = ((struct PropInfo *) gad->SpecialInfo)->HorizPot;
  94.  
  95.     if( vp->isfloat ) {
  96.         float temp;
  97.         temp = ( potvalue * (vp->maxfval - vp->minfval ))/ MAXPOT
  98.                 + vp->minfval;
  99.         vp->curfval = temp;
  100. #if !MANX
  101.         sprintf(dbuff,"%f   ", temp);
  102. #else
  103.         ftoa(temp, dbuff, sizeof(dbuff)-4, 1);
  104. #endif !MANX
  105.     }
  106.     else {
  107.         long temp;
  108.         temp = (long)( potvalue * (vp->maxival - vp->minival ))/ MAXPOT
  109.                 + vp->minival;
  110.         vp->curival = temp;
  111.         sprintf(dbuff,"%-12d", temp);
  112.     }
  113.     /*
  114.      * find '['
  115.      */
  116.     it = gad->GadgetText;
  117.     for( tx = (char *)it->IText; *tx && *tx != '['; tx++ ) {
  118.         ;
  119.     }
  120.     if( !*tx ) {
  121.         return; /* something screwy */
  122.     }
  123.     tx++; /* skip past opening bracket */
  124.     dx = dbuff;
  125.     while( *tx != ']' ) {
  126.         *tx++ = *dx++;
  127.     }
  128.  
  129.     if(exists){
  130.         long tempx, tempy;
  131.         tempx = it->LeftEdge + gad->LeftEdge;
  132.         tempy = it->TopEdge + gad->TopEdge + 6; /*fudge factor for baseline*/
  133.         Move( CntrlWin->RPort, tempx, tempy );
  134.         SetAPen(CntrlWin->RPort,it->FrontPen );
  135.         Text( CntrlWin->RPort, it->IText, strlen(it->IText ));
  136.     }
  137. }
  138.  
  139. void SetHourGlass() {
  140.     SetPointer( SurfWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  141.     SetPointer( GadWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  142.     SetPointer( CntrlWin, HourGlass, 16, 16, MPtrXOffset, MPtrYOffset);
  143. }
  144.  
  145. void ClearHourGlass() {
  146.     ClearPointer(SurfWin);
  147.     ClearPointer(GadWin);
  148.     ClearPointer(CntrlWin);
  149. }
  150.  
  151. void GadgetHandler(gadaddr)
  152.     struct Gadget *gadaddr;
  153. {
  154.     short curival;
  155.     float curfval;
  156.  
  157.     if( gadaddr->UserData ) {
  158.         GadgetUpdate( gadaddr, true );
  159.         curival = ((struct GadExtens *) gadaddr->UserData)->curival;
  160.         curfval = ((struct GadExtens *) gadaddr->UserData)->curfval;
  161.     }
  162.  
  163.     switch( (enum GadgetName) gadaddr->GadgetID ) {
  164.     case N_PtLocX:
  165.         LightSrc.x = (float)curival;
  166.         break;
  167.     case N_PtLocY:
  168.         LightSrc.y = (float)curival;
  169.         break;
  170.     case N_BackPlane:
  171.         BackColor = curival;
  172.         break;
  173.     case N_PtLocZ:
  174.         LightSrc.z = (float)curival;
  175.         break;
  176.     case N_BkIntens:
  177.         Ambience = curfval;
  178.         break;
  179.     case N_PtIntens:
  180.         PtIntensity = curfval;
  181.         break;
  182.     case N_Kdiffuse:
  183.         Kd = curfval;
  184.         break;
  185.     case N_Kspec:
  186.         Ks = curfval;
  187.         break;
  188.     case N_Map:
  189.         /* ResetCurve(); */
  190.         SetHourGlass();
  191.         RevMap();
  192.         ClearHourGlass();
  193.         break;
  194.     case N_Wire:
  195.         SetHourGlass();
  196.         RevNoShade();
  197.         ClearHourGlass();
  198.         break;
  199.     case N_Shaded:
  200.         SetHourGlass();
  201.         RevShade();
  202.         ClearHourGlass();
  203.         break;
  204.     case N_EditBez:
  205.         SetFitBez();
  206.         break;
  207.     case N_DefLines:
  208.         SetPolyDraw();
  209.         break;
  210.     case N_RevAngle:
  211.         SetRotRange( curival );
  212.         break;
  213.     case N_RevStart:
  214.         SetRotStart( curival );
  215.         break;
  216.     case N_TiltAng:
  217.         SetSecAng( curival );
  218.         break;
  219.     case N_RevSlices:
  220.         SetRevMesh( curival );
  221.         break;
  222.     case N_BezSlices:
  223.         SetBezMesh( curival );
  224.         break;
  225.     case N_SurfDist:
  226.         SetSurfDist( curival);
  227.         break;
  228.     case N_RepV:
  229.         MapRepV = curival;
  230.         PrepImgPix();
  231.         break;
  232.     case N_RepH:
  233.         MapRepH = curival;
  234.         PrepImgPix();
  235.         break;
  236.     case N_GoSurf:
  237.         ScreenToFront( SurfScrn );
  238.         break;
  239.     case N_GoPanel:
  240.         WBenchToFront();
  241.         WindowToFront( CntrlWin );
  242.         break;
  243.     default:
  244.         break;
  245.     }
  246. }
  247.